/**
 * 计算一个数的平方根
*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    float new_guess;
    float last_guess;
    float number;

    printf("请输入一个数字：");
    scanf("%f", &number);

    if(number<0){
        printf("请输入一个正数");
        return 1;
    }

    new_guess = 1;
    do{
        last_guess = new_guess;
        new_guess = (last_guess+number/last_guess)/2;
        printf("%.5e\n", new_guess);
    }while (new_guess != last_guess);
    
    printf("结果：%g 的平方根是 %g\n",number,new_guess);

    return 0;
}